import akshare as ak


def get_hs300_stock_codes():
    """
    获取沪深300股票代码列表
    :return:
    """
    hs300 = ak.index_stock_cons_sina("000300")
    codes = hs300.loc[:, ["symbol", "code", "name"]]
    # codes = codes.tolist()
    return codes


def get_zz500_stock_codes():
    """
    获取中正500股票代码列表
    :return:
    """
    zz500 = ak.index_stock_cons_sina("000905")
    # zz500 = ak.index_stock_cons("000300")
    # zz500 = ak.index_stock_cons("000905")
    print(zz500)
    codes = zz500.loc[:, ["品种代码", "品种名称"]]

    codes = zz500
    return codes


def get_hs300_zz500(code):
    cfg = ak.index_stock_cons(code)
    print(cfg)
    codes = cfg.loc[:, ["品种代码", "品种名称"]]
    return codes

def get_hs300_zz5002(code):
    # 000300 沪深300
    # 000905 中正500
    cfg = ak.index_stock_cons_sina(code)
    print(cfg)
    codes = cfg.loc[:, ["symbol", "code", "name"]]
    return codes


if __name__ == "__main__":
    # 获取沪深300代码列表
    code = get_zz500_stock_codes()
    print(code)

    # code = get_hs300_zz500("000300")
    # print(code)

    # code = get_hs300_zz500("000905")
    # print(code)
